package com.dm.shop.controller;


import com.dm.shop.entity.ShopCart;
import com.dm.shop.service.ShopCartService;
import com.dm.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MyBatisPlusGenerater-Saiya Wang
 * @since 2021-07-20
 */
@CrossOrigin
@RestController
@RequestMapping("/shopCart")
public class ShopCartController {
    @Autowired
    private ShopCartService shopCartService;

    @GetMapping("findShopCart/{uid}")
    @ApiOperation("通过用户的id购物车信息")
    public Result getShopCartInfo(@PathVariable("uid") int uid){
        return shopCartService.getShopCartInfo(uid);
    }

    @DeleteMapping("/del/{uid}/{pid}")
    @ApiOperation("根据uid和pid购物车")
    public Result delShopCartById(@PathVariable("uid") int uid,@PathVariable("pid") int pid){
        System.out.println("要删除东西的用户:"+uid);
        System.out.println("要删除的商品："+pid);
        return shopCartService.delShopCartById(uid,pid);
    }

    @DeleteMapping("/del/{uid}")
    @ApiOperation("清空购物车")
    public Result delAllShopCart(@PathVariable("uid") int uid){

        return shopCartService.delAllShopCart(uid);
    }

    @PostMapping("/addShopCart")
    @ApiOperation("添加购物车")
    public Result addShopCart(@RequestBody ShopCart shopCart){

        return shopCartService.addShopCart(shopCart);
    }


}
